#!/usr/bin/env node

const path = require('path')
const inquirer = require('inquirer')
const fs  = require('fs')
const ejs = require('ejs')
inquirer.prompt([
    {
        type: 'input',
        name: 'name',
        message: 'Project name?'
    }
]).then(answers => {
    console.log(answers)
    const tplDir = path.join(__dirname, 'templates')

    const destDir = process.cwd()

    fs.readdir(tplDir, (err, files) => {
        if (err) throw err
        files.forEach(file => {
            ejs.renderFile(path.join(tplDir, file), answers, (err, result) => {
                if (err) throw err
                console.log(result)
                fs.writeFileSync(path.join(destDir, file), result)
            })
        })
    })
})